<?php
session_start();

include "webmaster_connect.php";

$page_permission = 2;

include "webmaster_check_login.php";
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<style type="text/css">
body {
	background-image: url(../images/wood.jpg);
	background-repeat: repeat-x;
	margin: 0px;
	background-position: left top;
	background-attachment: fixed;
	background-color: #000000;
	padding-top: 0px;
	padding-right: 0px;
	padding-bottom: 0px;
	padding-left: 0px;
}
</style>
<link href="../css/webmaster_guest_alerts.css" rel="stylesheet" type="text/css" />
</head>

<body>

<div id="page_container">

<?php 

include "../admin_files/webmaster_header.php";
include "../admin_files/webmaster_navigation.php" 

?>

<div id="content_container">


<h1>Guest alerts:</h1>

<form id="date_filter" action="webmaster_customer_feedback.php" method="post" name="status_filter">

<label> Feedback status: 
<select name="feedback_status">
<option value="New">New</option>
<option value="Accepted">Accepted</option>
<option value="Rejected">Rejected</option>
<option value="All">All</option>
</select>
</label>

<input name="refresh_feedback" type="submit" value="Refresh" />

</form>

<table width="970px" border="0" cellpadding="3">

<tr>
	<th class="header" scope="col"></th>
    <th class="header" scope="col">Date</th>
    <th class="header" scope="col">Product ID</th>
    <th class="header" scope="col">Customer name</th>
    <th class="header" scope="col">Feedback</th>
    <th class="header" scope="col">Status</th>
  </tr>

<?php 
 
$status_filter = $_POST['feedback_status'];
 
$query = "SELECT *
		  FROM customer_feedback";

if(isset($_POST['feedback_status'])) //If status is posted then do below checks

{

	if ($status_filter != "All") //If filter selected is NOT "All"

	{
		$query .= ' WHERE feedback_status = "'.$status_filter.'"';
	}
	
}
		  
$query .= " ORDER BY feedback_id DESC";


//If the filter status isnt posted then display new feedback only
if(!isset($_POST['feedback_status']))

{

	$query = "SELECT * FROM customer_feedback WHERE feedback_status = 'New' ORDER BY feedback_id DESC";

	
}

$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
	
	$feedback_date = $row['feedback_date'];
	$feedback_date = date("d/m/Y", strtotime($feedback_date));
	
echo '

  <tr class="'.$row['feedback_status'].'">
	<th align="center">
		
		<form action="webmaster_change_feedback.php" method="post" name="amend_feedback">';
		
		if($row['feedback_status'] == "New")
		
		{
			echo '
			<select name="new_status">
			<option value="Accepted">Accepted</option>
			<option value="Rejected">Rejected</option>
			</select>
			';
		
		}
		
		echo '
		<input name="feedback_id" type="hidden" value="'.$row['feedback_id'].'" />
		<input name="current_status" type="hidden" value="'.$row['feedback_status'].'" />
		<input name="amend_feedback" type="submit" value="Change" />
		</form>
		
	</th>
	<th>'.$feedback_date.'</th>
	<th>'.$row['product_id'].'</th>
	<th>'.$row['customer_name'].'</th>
	<th>'.$row['feedback'].'</th>
	<th>'.$row['feedback_status'].'</th>
  </tr>

';
	
}


?>

</table>

<?php
/////////////////////////
//TESTING - Display query
/////////////////////////

//echo $query 

/////////////
//END Testing
/////////////

?>

</div>
<!--login_container-->

</div> 
<!--page_container-->

</body>
</html>

